﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using Draw.Interface;
using System.Windows.Media;
using Draw.Core;

namespace Draw.Implement
{
    public class LineShape : ElementBase
    {

        #region properties

        public Point StartPoint { set; get; }
        public Point EndPoint { set; get; }

        #endregion

        public LineShape():base()
        {
            
        }


        protected override void Init()
        {
            this._children = new VisualCollection(this);
            this.Pen = new Pen(Brushes.Red, 1);
            //this.MouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(LineShape_MouseLeftButtonDown);
            //this.MouseLeftButtonUp += new System.Windows.Input.MouseButtonEventHandler(LineShape_MouseLeftButtonUp);
           this._children.Add( CreateDrawingVisualLine());
        }

        void LineShape_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        }

        void LineShape_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Point pt = e.GetPosition((UIElement)sender);
            VisualTreeHelper.HitTest(this, null, null, new PointHitTestParameters(pt));
        }

        protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseMove(e);
            Point ptNow = e.GetPosition((UIElement)this);
        }


        protected DrawingVisual CreateDrawingVisualLine()
        {
            DrawingVisual drawingVisual = new DrawingVisual();

            using (DrawingContext drawingContext = drawingVisual.RenderOpen())
            {
                drawingContext.DrawLine(Pen, this.StartPoint, this.EndPoint);
            }
            return drawingVisual;

        }
      
    }
}
